#include <iostream>
using namespace std;

typedef struct Node
{
	int num;
	Node *next;
}Node;

void CreateList(Node *&list, int len)
{
	list = new Node();
	list->num = 1;
	Node *head, *p, *q;
	p = list;
	head = list;
	int number = 2;
	len--;
	while(len--)
	{
		q = new Node();
		q->num = number;
		number++;
		p->next = q;
		p = q;
	}
	p->next = head;
}

int KillMember(Node *&list, int intval)
{
	Node *p = list;
	int cnt= 1;
	while(p->next != p)
	{
		if(cnt==intval-1)
		{
			Node *q = p->next;
			p->next = p->next->next;
			delete(q);
			cnt = 0;
		}
		cnt++;
		p = p->next;
	}
	return p->num;
}

int main()
{
	Node *list;
	int n;
	int intval;
	cin >> n;
	cin >> intval;
	CreateList(list, n);
	cout << KillMember(list,intval);
	
	return 0;
} 
